Revision: 444
          http://xlw.svn.sourceforge.net/xlw/?rev=444&view=rev
Author:   ericehlers
Date:     2008-02-29 02:36:08 -0800 (Fri, 29 Feb 2008)

Log Message:
-----------
Update the handwritten example application from xlw version 1.x

Modified Paths:
--------------
    branches/xl12/xlw/xlwMSVC7/xlwMSVC.sln

Added Paths:
-----------
    branches/xl12/xlw/xlwExample/
    branches/xl12/xlw/xlwExample/xlwExample.cpp
    branches/xl12/xlw/xlwExample/xlwExample.xls
    branches/xl12/xlw/xlwMSVC7/xlwExample/
    branches/xl12/xlw/xlwMSVC7/xlwExample/xlwExample.vcproj

Added: branches/xl12/xlw/xlwExample/xlwExample.cpp
===================================================================
--- branches/xl12/xlw/xlwExample/xlwExample.cpp	                        (rev 0)
+++ branches/xl12/xlw/xlwExample/xlwExample.cpp	2008-02-29 10:36:08 UTC (rev 444)
@@ -0,0 +1,252 @@
+
+/*
+ Copyright (C) 1998, 1999, 2001, 2002 J\xE9r\xF4me Lecomte
+ Copyright (C) 2007 Eric Ehlers
+ 
+ This file is part of xlw, a free-software/open-source C++ wrapper of the
+ Excel C API - http://xlw.sourceforge.net/
+ 
+ xlw is free software: you can redistribute it and/or modify it under the
+ terms of the xlw license.  You should have received a copy of the
+ license along with this program; if not, please email xlw-users@...
+ 
+ This program is distributed in the hope that it will be useful, but WITHOUT
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ FOR A PARTICULAR PURPOSE.  See the license for more details.
+*/
+
+// $Id: xlwExample.cpp,v 1.12 2003/03/08 22:21:02 jlecomte Exp $
+
+#include <xlw/xlw.h>
+#include <iostream>
+#include <sstream>
+#include <vector>
+#include <xlw/Win32StreamBuf.h>
+
+Win32StreamBuf debuggerStreamBuf;
+std::streambuf *oldStreamBuf;
+
+extern "C"
+{
+
+  /*LPXLOPER*/ LPXLFOPER EXCEL_EXPORT xlCirc(XlfOper xlDiam)
+  {
+    EXCEL_BEGIN;
+    // Converts d to a double.
+    double ret=xlDiam.AsDouble();
+    // Multiplies it.
+    ret *= 3.14159;
+    // Returns the result as a XlfOper.
+    return XlfOper(ret);
+    EXCEL_END;
+  }
+
+  /*LPXLOPER*/ LPXLFOPER EXCEL_EXPORT xlConcat(XlfOper xlStr1, XlfOper xlStr2)
+  {
+    EXCEL_BEGIN;
+    // Converts the 2 strings.
+    std::wstring str1 = xlStr1.AsWstring();
+    std::wstring str2 = xlStr2.AsWstring();
+    // Returns the concatenation of the 2 string as a XlfOper.
+    std::wstring ret = str1+str2;
+    return XlfOper(ret);
+    EXCEL_END;
+  }
+
+  LPXLOPER EXCEL_EXPORT xlConcat4(XlfOper4 xlStr1, XlfOper4 xlStr2)
+  {
+    EXCEL_BEGIN;
+    // Converts the 2 strings.
+    std::string str1 = xlStr1.AsString();
+    std::string str2 = xlStr2.AsString();
+    // Returns the concatenation of the 2 string as a XlfOper.
+    std::string ret = str1+str2;
+    return XlfOper4(ret);
+    EXCEL_END;
+  }
+
+  LPXLOPER12 EXCEL_EXPORT xlConcat12(XlfOper12 xlStr1, XlfOper12 xlStr2)
+  {
+    EXCEL_BEGIN;
+    // Converts the 2 strings.
+    std::wstring str1 = xlStr1.AsWstring();
+    std::wstring str2 = xlStr2.AsWstring();
+    // Returns the concatenation of the 2 string as a XlfOper.
+    std::wstring ret = str1+str2;
+    return XlfOper12(ret);
+    EXCEL_END;
+  }
+
+  /*LPXLOPER*/ LPXLFOPER EXCEL_EXPORT xlStats(XlfOper xlTargetRange)
+  {
+    EXCEL_BEGIN;
+
+    // Temporary variables.
+    double averageTmp = 0.0;
+    double varianceTmp = 0.0;
+
+    // XlfExcel::Coerce method (internally called) will return to Excel
+    // if one of the cell was invalidated and need to be recalculated.
+    // Excel will calculate this cell and call again our function.
+    // Thus we copy first all the data to avoid to partially compute the
+    // average for nothing since one of the cell might be uncalculated.
+    std::vector<double> temp = xlTargetRange.AsDoubleVector(XlfOperImpl::RowMajor);
+
+    // All cells are copied. We do the actual work.
+    size_t popSize = temp.size();
+    for (size_t i = 0; i < popSize; ++i)
+    {
+      // sums the values.
+      averageTmp += temp[i];
+      // sums the squared values.
+      varianceTmp += temp[i] * temp[i];
+    }
+    // Initialization of the resultArray.
+    double resultArray[2];
+    // compute average.
+    double& average = resultArray[0];
+    average = averageTmp / popSize;
+    // compute variance
+    double& variance = resultArray[1];
+    variance = varianceTmp / popSize - average * average;
+    // Create the XlfOper returned with the resultArray containing the values.
+    return XlfOper(1,2,resultArray);
+
+    EXCEL_END;
+  }
+
+  /*! 
+   * Demonstrates how to detect that the function is called by
+   * the function wizard, and how to retrieve the coordinates
+   * of the caller cell
+   */
+  /*LPXLOPER*/ LPXLFOPER EXCEL_EXPORT xlIsInWiz()
+  {
+    EXCEL_BEGIN;
+
+	// Checks if called from the function wizard
+    if (XlfExcel::Instance().IsCalledByFuncWiz())
+      return XlfOper(true);
+
+	// Gets reference of the called cell
+    XlfOper res;
+    XlfExcel::Instance().Call(xlfCaller,res,0);
+    XlfRef ref=res.AsRef();
+
+	// Returns the reference in A1 format
+    std::ostringstream ostr;
+    char colChar='A'+ref.GetColBegin();
+    ostr << colChar << ref.GetRowBegin() + 1 << std::ends;
+    std::string address=ostr.str();
+
+    return XlfOper(address.c_str());
+
+    EXCEL_END;
+  }
+
+  /*!
+   * Registered as volatile to demonstrate how functions can be 
+   * recalculated automatically even if none of the arguments 
+   * have cahnged.
+   *
+   * \return the number of time the function has been called.
+   */
+  /*LPXLOPER*/ LPXLFOPER EXCEL_EXPORT xlNbCalls()
+  {
+    EXCEL_BEGIN;
+
+	static short nbCalls = 0;
+	++nbCalls;
+    return XlfOper(nbCalls);
+
+    EXCEL_END;
+  }
+
+  long EXCEL_EXPORT xlAutoOpen()
+  {
+    oldStreamBuf = std::cerr.rdbuf(&debuggerStreamBuf);
+    std::cerr << XLW__HERE__ << "std::cerr redirected to MSVC debugger" << std::endl;
+
+    // Displays a message in the status bar.
+    XlfExcel::Instance().SendMessage("Registering library...");
+
+    // Registers the function xlCirc.
+    // Variable description of type R (default).
+    XlfArgDesc diameter("diameter","Diameter of the circle");
+    // xlCirc function description function as Circ.
+    XlfFuncDesc circ("xlCirc","Circ","Computes the circumference of a circle","xlw Example");
+    // Set the diameter argument definition for circ.
+    circ.SetArguments(diameter);
+    // Registers the function circ.
+    circ.Register();
+
+    // Registers the function xlConcat.
+    // Argument descriptions.
+    XlfArgDesc concat_str1("string1","First string");
+    XlfArgDesc concat_str2("string2","Second string");
+    // xlConcat function description as concat.
+    XlfFuncDesc concat("xlConcat","Concat","Concatenate two strings in one","xlw Example");
+    // Set the arguments for the function. Note how you create a XlfArgDescList from
+    // two or more XlfArgDesc (operator+). You can not push the XlfArgDesc one by one.
+    concat.SetArguments(concat_str1+concat_str2);
+    // Registers the concat function.
+    concat.Register();
+
+    // Registers the function xlConcat4.
+    // Argument descriptions.
+    XlfArgDesc concat4_str1("string1","First string","P");
+    XlfArgDesc concat4_str2("string2","Second string","P");
+    // xlConcat function description as concat.
+    XlfFuncDesc concat4("xlConcat4","Concat4","Concatenate two strings in one","xlw Example",
+        XlfFuncDesc::RecalcPolicy::NotVolatile,false,"P");
+    // Set the arguments for the function. Note how you create a XlfArgDescList from
+    // two or more XlfArgDesc (operator+). You can not push the XlfArgDesc one by one.
+    concat4.SetArguments(concat4_str1+concat4_str2);
+    // Registers the concat function.
+    concat4.Register();
+
+    // Registers the function xlConcat12.
+    // Argument descriptions.
+    XlfArgDesc concat12_str1("string1","First string","Q");
+    XlfArgDesc concat12_str2("string2","Second string","Q");
+    // xlConcat function description as concat.
+    XlfFuncDesc concat12("xlConcat12","Concat12","Concatenate two strings in one","xlw Example",
+        XlfFuncDesc::RecalcPolicy::NotVolatile,false,"Q");
+    // Set the arguments for the function. Note how you create a XlfArgDescList from
+    // two or more XlfArgDesc (operator+). You can not push the XlfArgDesc one by one.
+    concat12.SetArguments(concat12_str1+concat12_str2);
+    // Registers the concat function.
+    concat12.Register();
+
+    // Registers the function xlStats.
+    // Argument descriptions.
+    XlfArgDesc pop("Population","Target range containing the population");
+    // xlStats Function description
+    XlfFuncDesc stats("xlStats","Stats","returns a (1x2) range containing the average and the variance of a numeric population","xlw Example");
+    // Sets the arguments for the function.
+    stats.SetArguments(pop);
+    // Registers the stats function.
+    stats.Register();
+
+    // Registers the function xlIsInWiz.
+    XlfFuncDesc isInWiz("xlIsInWiz","IsInWiz","returns true if the function is called from the function wizard, and the address of the caller otherwise","xlw Example");
+    isInWiz.Register();
+
+	// Registers the function xlNumberOfCall as volatile (unconditionally recalculated)
+    XlfFuncDesc nbCalls("xlNbCalls","NbCalls","returns the number of time the function has been calculated since the xll was loaded (volatile)","xlw Example",XlfFuncDesc::Volatile);
+    nbCalls.Register();
+	
+    // Clears the status bar.
+    XlfExcel::Instance().SendMessage();
+    return 1;
+  }
+
+  long EXCEL_EXPORT xlAutoClose()
+  {
+    std::cerr << XLW__HERE__ << "Releasing ressources" << std::endl;
+    delete &XlfExcel::Instance();
+    std::cerr.rdbuf(oldStreamBuf);
+    return 1;
+  }
+
+}


Property changes on: branches/xl12/xlw/xlwExample/xlwExample.cpp
___________________________________________________________________
Name: svn:eol-style
   + native

Added: branches/xl12/xlw/xlwExample/xlwExample.xls
===================================================================
(Binary files differ)


Property changes on: branches/xl12/xlw/xlwExample/xlwExample.xls
___________________________________________________________________
Name: svn:needs-lock
   + *
Name: svn:mime-type
   + application/vnd.ms-excel

Added: branches/xl12/xlw/xlwMSVC7/xlwExample/xlwExample.vcproj
===================================================================
--- branches/xl12/xlw/xlwMSVC7/xlwExample/xlwExample.vcproj	                        (rev 0)
+++ branches/xl12/xlw/xlwMSVC7/xlwExample/xlwExample.vcproj	2008-02-29 10:36:08 UTC (rev 444)
@@ -0,0 +1,125 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+	ProjectType="Visual C++"
+	Version="7.10"
+	Name="xlwExample"
+	ProjectGUID="{EFB27940-60B1-4EA4-BE89-4214EB4231C0}"
+	Keyword="Win32Proj">
+	<Platforms>
+		<Platform
+			Name="Win32"/>
+	</Platforms>
+	<Configurations>
+		<Configuration
+			Name="Debug|Win32"
+			OutputDirectory="Debug"
+			IntermediateDirectory="Debug"
+			ConfigurationType="2"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				Optimization="0"
+				AdditionalIncludeDirectories="..\.."
+				PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;XLWEXAMPLE_EXPORTS"
+				MinimalRebuild="TRUE"
+				BasicRuntimeChecks="3"
+				RuntimeLibrary="3"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="4"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="xlwLib.lib"
+				OutputFile="$(OutDir)/xlwExample.xll"
+				LinkIncremental="2"
+				AdditionalLibraryDirectories="..\xlwLib\Debug"
+				GenerateDebugInformation="TRUE"
+				ProgramDatabaseFile="$(OutDir)/xlwExample.pdb"
+				SubSystem="2"
+				ImportLibrary="$(OutDir)/xlwExample.lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+		<Configuration
+			Name="Release|Win32"
+			OutputDirectory="Release"
+			IntermediateDirectory="Release"
+			ConfigurationType="2"
+			CharacterSet="2">
+			<Tool
+				Name="VCCLCompilerTool"
+				AdditionalIncludeDirectories="..\.."
+				PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;XLWEXAMPLE_EXPORTS"
+				RuntimeLibrary="2"
+				UsePrecompiledHeader="0"
+				WarningLevel="3"
+				Detect64BitPortabilityProblems="TRUE"
+				DebugInformationFormat="3"/>
+			<Tool
+				Name="VCCustomBuildTool"/>
+			<Tool
+				Name="VCLinkerTool"
+				AdditionalDependencies="xlwLib.lib"
+				OutputFile="$(OutDir)/xlwExample.xll"
+				LinkIncremental="1"
+				AdditionalLibraryDirectories="..\xlwLib\Release"
+				GenerateDebugInformation="TRUE"
+				SubSystem="2"
+				OptimizeReferences="2"
+				EnableCOMDATFolding="2"
+				ImportLibrary="$(OutDir)/xlwExample.lib"
+				TargetMachine="1"/>
+			<Tool
+				Name="VCMIDLTool"/>
+			<Tool
+				Name="VCPostBuildEventTool"/>
+			<Tool
+				Name="VCPreBuildEventTool"/>
+			<Tool
+				Name="VCPreLinkEventTool"/>
+			<Tool
+				Name="VCResourceCompilerTool"/>
+			<Tool
+				Name="VCWebServiceProxyGeneratorTool"/>
+			<Tool
+				Name="VCXMLDataGeneratorTool"/>
+			<Tool
+				Name="VCWebDeploymentTool"/>
+			<Tool
+				Name="VCManagedWrapperGeneratorTool"/>
+			<Tool
+				Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+		</Configuration>
+	</Configurations>
+	<References>
+	</References>
+	<Files>
+		<File
+			RelativePath="..\..\xlwExample\xlwExample.cpp">
+		</File>
+	</Files>
+	<Globals>
+	</Globals>
+</VisualStudioProject>


Property changes on: branches/xl12/xlw/xlwMSVC7/xlwExample/xlwExample.vcproj
___________________________________________________________________
Name: svn:eol-style
   + CRLF

Modified: branches/xl12/xlw/xlwMSVC7/xlwMSVC.sln
===================================================================
--- branches/xl12/xlw/xlwMSVC7/xlwMSVC.sln	2008-02-29 10:25:46 UTC (rev 443)
+++ branches/xl12/xlw/xlwMSVC7/xlwMSVC.sln	2008-02-29 10:36:08 UTC (rev 444)
@@ -18,6 +18,11 @@
 		{C2CD945C-BFFA-48E9-A1C2-BB39D014581D} = {C2CD945C-BFFA-48E9-A1C2-BB39D014581D}
 	EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "xlwExample", "xlwExample\xlwExample.vcproj", "{EFB27940-60B1-4EA4-BE89-4214EB4231C0}"
+	ProjectSection(ProjectDependencies) = postProject
+		{EF0259A5-FE0B-4B45-84E3-87D8822F51EC} = {EF0259A5-FE0B-4B45-84E3-87D8822F51EC}
+	EndProjectSection
+EndProject
 Global
 	GlobalSection(SolutionConfiguration) = preSolution
 		Debug = Debug
@@ -42,6 +47,10 @@
 		{C7C8EB2B-A31A-4219-8CF7-4F69DD4890EF}.Debug.Build.0 = Debug|Win32
 		{C7C8EB2B-A31A-4219-8CF7-4F69DD4890EF}.Release.ActiveCfg = Release|Win32
 		{C7C8EB2B-A31A-4219-8CF7-4F69DD4890EF}.Release.Build.0 = Release|Win32
+		{EFB27940-60B1-4EA4-BE89-4214EB4231C0}.Debug.ActiveCfg = Debug|Win32
+		{EFB27940-60B1-4EA4-BE89-4214EB4231C0}.Debug.Build.0 = Debug|Win32
+		{EFB27940-60B1-4EA4-BE89-4214EB4231C0}.Release.ActiveCfg = Release|Win32
+		{EFB27940-60B1-4EA4-BE89-4214EB4231C0}.Release.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 	EndGlobalSection


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.

